package com.example.springboot_jap_model.controller;

import com.example.springboot_jap_model.domain.RespEntity;
import com.example.springboot_jap_model.enums.RespEntityEnum;
import com.example.springboot_jap_model.exception.AutoException;
import com.example.springboot_jap_model.utils.RespEntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {

    /**
     * 打印日志
     */
    private final static Logger logger = LoggerFactory.getLogger(IndexController.class);
    /**
     * 登录
     * @return
     */
    @RequestMapping({"/","/login"})
    public String login(){
        return "login";
    }

    /**
     * 测试
     * @param says
     * @return
     */
    @PostMapping("/hello")
    @ResponseBody
    public RespEntity hello(@RequestParam("say")String says){
        if (says.length() >4) {
            throw new AutoException(RespEntityEnum.TEST);
        }
        return RespEntityUtils.success(says);
    }
}
